<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增中台配置系统')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-centreSysConfig-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">系统名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" maxlength="20" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">英文名：</label>
                <div class="col-sm-8">
                    <input name="englishName" class="form-control" maxlength="50" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">产品线：</label>
                <div class="col-sm-8">
                    <input name="productLine" class="form-control" type="text" maxlength="10" required>
                </div>
            </div>

            <div class="form-group">

                <label class="col-sm-3 control-label is-required">地区：</label>
                <input type="hidden" id="areaId" name="areaId">
                <div class="col-sm-8">
                    <div class='input-group'>
                    <input name="title" id="title" class="form-control" type="text" readonly>
                    <span  id="selectDictTree" class='input-group-addon input-sm' onclick='selectDictTree("", this)'>
                                <i class='fa fa-search' >选择</i>
                    </span>
                    </div>
                </div>
            </div>

            <!--<div class="form-group">
                <label class="col-sm-3 control-label">城市：</label>
                <div class="col-sm-8">
                    <select name="city" class="form-control m-b" th:with="type=${@dict.getType('centre_sys_city')}" >
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">系统环境类型：</label>
                <div class="col-sm-8">
                    <select name="sysType" class="form-control m-b" th:with="type=${@dict.getType('sys_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>

            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">回调url：</label>
                <div class="col-sm-8">
                    <input name="callBackUrl" class="form-control" type="text" maxlength="100" required>
                </div>
            </div>-->
<!--
            <div class="form-group">
                <label class="col-sm-3 control-label is-required">登录页图片地址：</label>
                <div class="col-sm-8">
                    <input name="loginLogo" id="loginLogo" class="form-control" type="hidden" required>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test1">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo1" style="width: 100%;">
                            <p id="demoText"></p>
                        </div>
                    </div>
                </div>
            </div>-->

            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">登录页图片地址：</label>
                <div class="col-sm-8">
                    <input name="loginLogo" class="form-control" type="text" required>
                </div>
            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">logo页图片地址：</label>
                <div class="col-sm-8">
                    <input name="logo" id="logo" class="form-control" type="hidden" required>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test2">上传图片</button>
                        <div class="layui-upload-list">
                            <img class="layui-upload-img" id="demo2" style="width: 100%;">
                            <p id="demoText2"></p>
                        </div>
                    </div>
                </div>
            </div>

            <!--<div class="form-group">
                <label class="col-sm-3 control-label is-required">logo图片地址：</label>
                <div class="col-sm-8">
                    <input name="logo" class="form-control" type="text" required>
                </div>
            </div>-->

            <div class="form-group">    
                <label class="col-sm-3 control-label">排序值：</label>
                <div class="col-sm-8">
                    <input name="sortValue" class="form-control" type="number" maxlength="5">
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "centre/centreSysConfig"
        $("#form-centreSysConfig-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {

                /*if ($.common.isEmpty($('#loginLogo').val())){
                    $.modal.alertWarning("请输上传登录页图片。");
                    return;
                }*/
                if ($.common.isEmpty($('#logo').val())){
                    $.modal.alertWarning("请输上传logo图片。");
                    return;
                }
                $.operate.save(prefix + "/add", $('#form-centreSysConfig-add').serialize());
            }
        }
/*

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test1'
                ,url: ctx + "common/upload" //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        debugger
                        $('#demo1').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#loginLogo').val(res.fileName); //图片路径
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });
*/

        layui.use('upload', function(){
            var $ = layui.jquery
                ,upload = layui.upload;

            //普通图片上传
            var uploadInst = upload.render({
                elem: '#test2'
                ,url: ctx + "common/upload" //改成您自己的上传接口
                ,before: function(obj){
                    //预读本地文件示例，不支持ie8
                    obj.preview(function(index, file, result){
                        debugger
                        $('#demo2').attr('src', result); //图片链接（base64）
                    });
                }
                ,done: function(res){
                    //如果上传失败
                    if(res.code > 0){
                        return layer.msg('上传失败');
                    }
                    //上传成功
                    $('#logo').val(res.fileName); //图片路径
                }
                ,error: function(){
                    //演示失败状态，并实现重传
                    var demoText = $('#demoText2');
                    demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                    demoText.find('.demo-reload').on('click', function(){
                        uploadInst.upload();
                    });
                }
            });
        });



        // 选择字典处理函数
        function selectDictTree(columnId, obj) {
            // alert("awefwewfew");
            var url = ctx + "hr/area/selectTree";
            var options = {
                title: '权限地区',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            debugger
            var body = layer.getChildFrame('body', index);
            var areaId = body.find('#id').val();
            var title = body.find('#title').val();

            layer.close(index);
            $("#areaId").val(areaId);
            $("#title").val(title);
        }


    </script>
</body>
</html>